{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "from lxml import etree\n",
    "# url = 'http://bj.ganji.com/ershoufang/'\n",
    "url = 'https://bj.58.com/ershoufang/'\n",
    "\n",
    "headers = {\n",
    "    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',\n",
    "}\n",
    "response = requests.get(url, headers=headers)\n",
    "html = etree.HTML(response.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def write_file(content:str):\n",
    "    filename = '二手房数据.csv'\n",
    "    with open(filename, 'a+', encoding='gbk', errors='ignore') as file:\n",
    "        file.write(content)\n",
    "        file.write('\\n')\n",
    "        \n",
    "## w 覆盖写入\n",
    "## wb 二进制写入\n",
    "## a+ 追加写入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120\n"
     ]
    }
   ],
   "source": [
    "li_list = html.xpath('.//li[@class=\"sendsoj\"]')\n",
    "print(len(li_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['西绒线小区，给您意想不到的惊喜价位\\xa0'] ['849'] ['万'] ['116302元/㎡'] ['73.0㎡\\xa0', '距2号线和平门步行706m'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['西山美墅馆 下叠拼别墅 正规大四居 超大花园\\xa0'] ['1899'] ['万'] ['80178元/㎡'] ['236.85㎡\\xa0'] ['4室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['临河观景，5G智能社区 运河CBD步行1000米\\xa0'] ['518'] ['万'] ['58203元/㎡'] ['89.0㎡\\xa0', '距八通线通州北苑步行1.4km'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['龙湖长城源著二期，空气清新，环境优雅，可托管\\xa0'] ['70'] ['万'] ['21440元/㎡'] ['32.65㎡\\xa0'] ['1室0厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['定慧桥八里庄北里 东西通透朝向 2室 不临街\\xa0'] ['545'] ['万'] ['91751元/㎡'] ['59.4㎡\\xa0', '距6号线慈寿寺步行711m'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['东二环 东南两居 丽舍 精装修  只此一套  服\\xa0'] ['1018'] ['万'] ['125944元/㎡'] ['80.83㎡\\xa0', '距1号线永安里步行957m'] ['2室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['昌平，北京风景120平482万，3室2卫，大阳台\\xa0'] ['482'] ['万'] ['41222元/㎡'] ['116.93㎡\\xa0', '距昌平线南邵步行1.5km'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['满五 电梯房 58平 大河庄苑 房东急置换 诚意\\xa0'] ['500'] ['万'] ['86207元/㎡'] ['58.0㎡\\xa0', '距10号线苏州街步行1.9km'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['中国铁建原香漫谷二区 电梯房 满二唯一住房 南北\\xa0'] ['205'] ['万'] ['23034元/㎡'] ['89.0㎡\\xa0', '距燕房线马各庄步行1.9km'] ['3室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['业主着急用钱，十万火急，价格还能商量急卖亦庄金茂\\xa0'] ['735'] ['万'] ['49000元/㎡'] ['150.0㎡\\xa0'] ['4室2厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['1400万 精装修 南北通透 4室2厅 诚心出售\\xa0'] ['1400'] ['万'] ['82353元/㎡'] ['170.0㎡\\xa0'] ['4室2厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['世纪城三期晨月园 2室1厅1卫 格局方正 品质小\\xa0'] ['745'] ['万'] ['75253元/㎡'] ['99.0㎡\\xa0', '距12号线长春桥步行1.3km'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['5室4厅 豪华装修 1060万 满五唯一住房 诚\\xa0'] ['1060'] ['万'] ['39406元/㎡'] ['269.0㎡\\xa0'] ['5室4厅4卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['好房要淘 好房难得 进来看看 五星经纪人为您服务\\xa0'] ['250'] ['万'] ['24272元/㎡'] ['103.0㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['莱蒙湖新出联排别墅  满五一 南北向 状况好 可\\xa0'] ['1300'] ['万'] ['41010元/㎡'] ['317.0㎡\\xa0', '距15号线国展步行1.4km'] ['3室2厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['首开璞瑅墅户型方正 1200万485平毛坯现房实\\xa0'] ['1600'] ['万'] ['32990元/㎡'] ['485.0㎡\\xa0'] ['6室4厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['行宫园 南北通透 税费少 两居\\xa0'] ['185'] ['万'] ['25585元/㎡'] ['72.31㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['美林双拼别墅，450平5居室，400平花园，临水\\xa0'] ['2200'] ['万'] ['73334元/㎡'] ['300.0㎡\\xa0'] ['5室3厅4卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['诚卖价可谈 660 东直门南大街双朝南两室一厅 \\xa0'] ['671'] ['万'] ['96353元/㎡'] ['69.64㎡\\xa0', '距2号线东直门步行516m'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['（雪区房） 低层 单价2.1万 就一个契税 看房\\xa0'] ['235'] ['万'] ['20806元/㎡'] ['112.95㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['南五环 大兴 瀛海地铁 精装新房  中海寰宇时代\\xa0'] ['364'] ['万'] ['52000元/㎡'] ['70.0㎡\\xa0', '距8号线南段瀛海步行353m'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['新出凯盛南向一居室 无遮挡开放厨房 地暖\\xa0'] ['285'] ['万'] ['47500元/㎡'] ['60.0㎡\\xa0'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['171平 440万 4室2厅 特色好房 立汤路北\\xa0'] ['440'] ['万'] ['25731元/㎡'] ['171.0㎡\\xa0'] ['4室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['香山艺墅 实用480平米 联排山水别墅 性价比高\\xa0'] ['2500'] ['万'] ['86912元/㎡'] ['287.65㎡\\xa0'] ['5室3厅6卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['鹿鸣苑联排别墅 930万匠心装修 南北通透四居室\\xa0'] ['930'] ['万'] ['40701元/㎡'] ['228.5㎡\\xa0', '距亦庄线万源街步行863m'] ['4室3厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北京东 香河首付6万 总价27万起 有高铁 有地\\xa0'] ['48'] ['万'] ['7273元/㎡'] ['66.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['（热推）行宫南区中层单价1.9   四室两厅两位\\xa0'] ['240'] ['万'] ['19015元/㎡'] ['126.22㎡\\xa0'] ['4室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['西山美墅馆 内置电梯  三车位 大五居室 使用面\\xa0'] ['2500'] ['万'] ['59846元/㎡'] ['417.74㎡\\xa0'] ['5室3厅6卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['精装修 宾阳里小区 65平 2室1厅 165万 \\xa0'] ['165'] ['万'] ['25280元/㎡'] ['65.27㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['电梯房 153平 3室2厅 320万 南北通透 \\xa0'] ['320'] ['万'] ['20916元/㎡'] ['153.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['业主只让我们卖 东南北两居室 中层 新社区 近地\\xa0'] ['630'] ['万'] ['70787元/㎡'] ['89.0㎡\\xa0', '距15号线望京西步行1.2km'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['芍药居北里次新房两居室 业主急售 小区正中间前后\\xa0'] ['660'] ['万'] ['73309元/㎡'] ['90.03㎡\\xa0', '距17号线望京西步行363m'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['中信新城两*区 满五两居室\\xa0'] ['274'] ['万'] ['38657元/㎡'] ['70.88㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['云岗南宫智苑 精装 复式两居室 可做三居使用 仅\\xa0'] ['295'] ['万'] ['35980元/㎡'] ['81.99㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['远洋天地 正规小两居 精装修可拎包入住 满二高原\\xa0'] ['560'] ['万'] ['71275元/㎡'] ['78.57㎡\\xa0', '距1号线四惠步行658m'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['四环边南十里居 中间层 南向正规2居室 精装修 \\xa0'] ['305'] ['万'] ['57127元/㎡'] ['53.39㎡\\xa0', '距14号线(东)东风北桥步行1.3km'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['顺鑫澜庭 86平米228万南北通透两居室，一层带\\xa0'] ['228'] ['万'] ['26698元/㎡'] ['85.4㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['房山 城关 看房方便 一居小户型 诚心出售 看房\\xa0'] ['88'] ['万'] ['22565元/㎡'] ['39.0㎡\\xa0', '距燕房线老城区步行1.2km'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['南海家园三里 采光足带电梯 户型房子\\xa0'] ['285'] ['万'] ['31773元/㎡'] ['89.7㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['急用钱 全明格局 别墅区 花园洋房 南北通透 大\\xa0'] ['87'] ['万'] ['8788元/㎡'] ['99.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['朝青 低于市场300万正中间位置 前后观景 双卧\\xa0'] ['2100'] ['万'] ['72917元/㎡'] ['288.0㎡\\xa0', '距6号线青年路步行1.1km'] ['3室2厅4卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['久润花园东区 四室四厅四卫 两代人住 互不打扰 \\xa0'] ['425'] ['万'] ['17502元/㎡'] ['242.83㎡\\xa0'] ['4室4厅4卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['大兴南雄 安周边景区房特价3999外地人可买可贷\\xa0'] ['46'] ['万'] ['4792元/㎡'] ['96.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['6318羊耳峪 901快直达前门 交通便利 86\\xa0'] ['86'] ['万'] ['14099元/㎡'] ['61.0㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['梨园城铁八通线100米园景东区精装两居室满五唯一\\xa0'] ['315'] ['万'] ['42034元/㎡'] ['74.94㎡\\xa0', '距八通线梨园步行488m'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['宾阳新北里现代精装 正规三室110平220万诚心\\xa0'] ['220'] ['万'] ['20245元/㎡'] ['108.67㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['大兴机场旁 外地可买可贷 首付低 紧邻高速高铁 \\xa0'] ['22.6'] ['万'] ['3425元/㎡'] ['66.0㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['距高铁站500米17芬直达北京南三环霸州市重点养\\xa0'] ['36'] ['万'] ['3530元/㎡'] ['102.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['全款16万，外地可买，京南养老现房，交通便利，送\\xa0'] ['20'] ['万'] ['4167元/㎡'] ['48.0㎡\\xa0'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['70年产权 临近高铁 外地人可购 交通便利 成熟\\xa0'] ['46.5'] ['万'] ['3720元/㎡'] ['125.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['业主诚意出售，看上价格能谈，满五年唯一住房 税费\\xa0'] ['426'] ['万'] ['33282元/㎡'] ['128.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['京南特价房，首付5万，可注 册公司，现房送精装，\\xa0'] ['41'] ['万'] ['7455元/㎡'] ['55.0㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['360万！角门东阳光花园社区  2010新社区 \\xa0'] ['568'] ['万'] ['63119元/㎡'] ['89.99㎡\\xa0', '距10号线角门东步行357m'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['武圣东里 南北通透2室1厅 满五唯一 298万一\\xa0'] ['305'] ['万'] ['50749元/㎡'] ['60.1㎡\\xa0', '距10号线潘家园步行945m'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['京南高铁站现房均价3000！外地可买可贷二十分进\\xa0'] ['26'] ['万'] ['3059元/㎡'] ['85.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['精装修 朝南 77平 电梯房 房东急置换 诚意买\\xa0'] ['98'] ['万'] ['12728元/㎡'] ['77.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['石园东区~格局方正~诚意出售~低总价~推荐房源\\xa0'] ['245'] ['万'] ['35293元/㎡'] ['69.42㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['新机场南现房4000送装修送小院三个月下房本紧邻\\xa0'] ['27'] ['万'] ['3858元/㎡'] ['70.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['高层   电梯房  通透 三居 131平 305\\xa0'] ['305'] ['万'] ['23283元/㎡'] ['131.0㎡\\xa0', '距房山线良乡南关步行1.3km'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北京南4A景区旁现房3999通透两居三居可选高铁\\xa0'] ['40'] ['万'] ['4167元/㎡'] ['96.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['绿地西斯莱别墅区后面，高楼层，视野特别好，采光特\\xa0'] ['712'] ['万'] ['53749元/㎡'] ['132.47㎡\\xa0', '距4号线大兴线高米店南步行610m'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['东花市北里中区 2室1厅1卫 价格可谈 满五 公\\xa0'] ['548'] ['万'] ['81006元/㎡'] ['67.65㎡\\xa0', '距7号线广渠门内步行764m'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北京 通州副中心 近地铁  低首付 两层真复式 \\xa0'] ['39'] ['万'] ['9750元/㎡'] ['40.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['房山区燕山  羊耳峪里 小户型位置好 明厨明卫 \\xa0'] ['80'] ['万'] ['17942元/㎡'] ['44.59㎡\\xa0'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['永清临空区 新盘特价6800起 无电商紧邻机场D\\xa0'] ['65'] ['万'] ['8025元/㎡'] ['81.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['壹号院南区中心位置 800万豪装 附赠两个车位 \\xa0'] ['3300'] ['万'] ['93908元/㎡'] ['351.41㎡\\xa0', '距16号线马连洼步行1.9km'] ['4室2厅4卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['免指标叠拼别墅实用200平买挑高8.1八大处脚下\\xa0'] ['695'] ['万'] ['60435元/㎡'] ['115.0㎡\\xa0'] ['4室3厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['特价7500现房 通透二居 温泉入户 免费游泳池\\xa0'] ['50'] ['万'] ['7353元/㎡'] ['68.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['宜居1万1  新贤家园 三居双卫楼间距大近一下三\\xa0'] ['530'] ['万'] ['41644元/㎡'] ['127.27㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北京南 特价3400一层带小院 一户一本 现房 \\xa0'] ['33'] ['万'] ['3268元/㎡'] ['101.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['雄 安东五证齐全特价3999一平紧邻景区小区内部\\xa0'] ['38'] ['万'] ['4750元/㎡'] ['80.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['可改3居的商品房  潞河运河\\xa0'] ['320'] ['万'] ['35751元/㎡'] ['89.51㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['长阳碧桂园南北双通透246万两居业主诚意出售\\xa0'] ['246'] ['万'] ['27984元/㎡'] ['87.91㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['雄~安新区霸州现房全款24万送车位送花园紧邻高铁\\xa0'] ['31.3'] ['万'] ['3069元/㎡'] ['102.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['70年产权~大兴机场新的临空区~百川格外~复式现\\xa0'] ['40.88'] ['万'] ['8176元/㎡'] ['50.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北京新亦庄旁 临空经济区 紧邻地铁 现房即买即住\\xa0'] ['45'] ['万'] ['8824元/㎡'] ['51.0㎡\\xa0'] ['2室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['（新上低总价）八角北路，全南向两居室，满五年唯一\\xa0'] ['219'] ['万'] ['43128元/㎡'] ['50.78㎡\\xa0', '距1号线古城步行2km'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['国瑞生态城(别墅)5室3厅4卫\\xa0'] ['369'] ['万'] ['14880元/㎡'] ['248.0㎡\\xa0'] ['5室3厅4卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北京风景 底层大两居 南北通透 花园社区 出行便\\xa0'] ['420'] ['万'] ['35898元/㎡'] ['117.0㎡\\xa0', '距昌平线南邵步行1.5km'] ['3室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['燕化星城健德二里  一层两居室出售，看房方便\\xa0'] ['199'] ['万'] ['25939元/㎡'] ['76.72㎡\\xa0', '距燕房线星城步行1km'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['190万 潘家园小区(怀柔) 满五唯一住房 南北\\xa0'] ['190'] ['万'] ['27942元/㎡'] ['68.0㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['大兴南 两居首付8万外地可买交通便利配套齐全2个\\xa0'] ['34'] ['万'] ['3542元/㎡'] ['96.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['馨港二区 电梯房 一层带花园 南北通透 紧邻大门\\xa0'] ['395'] ['万'] ['27817元/㎡'] ['142.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['雄 安新区旁 紧邻地铁邻国道，高铁站，配套齐，可\\xa0'] ['45'] ['万'] ['6618元/㎡'] ['68.0㎡\\xa0'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['顺鑫澜庭 86平米228万南北通透两居室，一层带\\xa0'] ['228'] ['万'] ['26698元/㎡'] ['85.4㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北京东 副中心旁燕郊 大产权外地人可按揭地铁 房\\xa0'] ['98'] ['万'] ['11489元/㎡'] ['85.3㎡\\xa0'] ['2室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['1995年房~川北~南北通透~精装修两居~干净整\\xa0'] ['148'] ['万'] ['24371元/㎡'] ['60.73㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['天津西站旁 首付14万起 外地当天入住 公交 高\\xa0'] ['40'] ['万'] ['3704元/㎡'] ['108.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['进京检查站南10公里 特价6700元 一层送小院\\xa0'] ['58'] ['万'] ['7161元/㎡'] ['81.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['京南 雄北 紧邻机场 高铁 特价房送小院！ 菜地\\xa0'] ['25'] ['万'] ['3165元/㎡'] ['79.0㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['大兴机场旁洋房特价6700起！空港经济区高品质社\\xa0'] ['55'] ['万'] ['7424元/㎡'] ['74.09㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['海淀 四季青 1室1厅 30平 175万 电梯房\\xa0'] ['175'] ['万'] ['57756元/㎡'] ['30.3㎡\\xa0', '距6号线廖公庄步行539m'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['碧桐园 新房未入住 精装两居室 送阁楼送18平露\\xa0'] ['260'] ['万'] ['60116元/㎡'] ['43.25㎡\\xa0', '距6号线廖公庄步行539m'] ['2室1厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['大兴南永清高铁通勤房一层带50平小院~认购送菜地\\xa0'] ['38'] ['万'] ['3800元/㎡'] ['100.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['西城神盘 荣丰2008 南北通小开间 满五唯一 \\xa0'] ['341'] ['万'] ['142084元/㎡'] ['24.0㎡\\xa0', '距7号线达官营步行578m'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['果园西里 精装修 两室两厅一卫 五年唯一 售18\\xa0'] ['185'] ['万'] ['20151元/㎡'] ['91.81㎡\\xa0'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['38号院三层 93平 220万 3室2厅 南北通\\xa0'] ['220'] ['万'] ['23656元/㎡'] ['93.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['外地可买可贷 地铁站附近 送精装 现房 配套齐全\\xa0'] ['64.3'] ['万'] ['6990元/㎡'] ['92.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['准现房均价3800送小院送精装送车位五证齐全北京\\xa0'] ['35'] ['万'] ['3609元/㎡'] ['97.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['（185万可议）老业主高层南向 不临街诚售 看房\\xa0'] ['333'] ['万'] ['60217元/㎡'] ['55.3㎡\\xa0', '距亦庄线亦庄文化园步行484m'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['熙悦林语，精装大上叠，两叠之上叠，仅有一套的房子\\xa0'] ['1126'] ['万'] ['43308元/㎡'] ['260.0㎡\\xa0', '距8号线南段五福堂步行2km'] ['4室2厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['K2玉兰湾 2016新社区 四居毛坯 无遮挡 随\\xa0'] ['1175'] ['万'] ['50560元/㎡'] ['232.4㎡\\xa0', '距八通线九棵树步行589m'] ['4室1厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['总价低急售(满五年，地铁盘)苏庄片区单价2500\\xa0'] ['260'] ['万'] ['24955元/㎡'] ['104.19㎡\\xa0', '距房山线苏庄步行852m'] ['3室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北京顺义，首都机场  现房送精装 万科物业 直接\\xa0'] ['145'] ['万'] ['16478元/㎡'] ['88.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['（就这套便宜）康居南区 精装修拎包入住 独立三室\\xa0'] ['190'] ['万'] ['20653元/㎡'] ['92.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['南四环边上 宣颐家园南北电梯大三居 客厅双阳台 \\xa0'] ['625'] ['万'] ['47238元/㎡'] ['132.31㎡\\xa0', '距亦庄线旧宫步行1.5km'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['金色白一 青春路九院 2室1厅 195万元 精装\\xa0'] ['195'] ['万'] ['33007元/㎡'] ['59.08㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['滨河小区大2居~婚房装修~朝向采光好~南北通透 \\xa0'] ['235'] ['万'] ['39167元/㎡'] ['60.0㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['杨镇顺鑫朗郡，业主已定房价钱大商量，一天没住过，\\xa0'] ['325'] ['万'] ['27543元/㎡'] ['118.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['福成五期94平米正规三居室135万中间楼层满两年\\xa0'] ['135'] ['万'] ['14211元/㎡'] ['95.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['北街家园六区 两居室首付100万 自住精装修 全\\xa0'] ['283'] ['万'] ['46886元/㎡'] ['60.36㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['孔雀城精装复试房，空中小别墅首付15万紧邻CBD\\xa0'] ['64'] ['万'] ['10000元/㎡'] ['64.0㎡\\xa0'] ['2室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['（可看）西南三环精装现房 金融街丽泽商务区 5G\\xa0'] ['2035'] ['万'] ['110000元/㎡'] ['185.0㎡\\xa0', '距16号线丰益桥南步行500m'] ['4室2厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['豪装下跃！南北双花园60平米 有车位 婚房装修 \\xa0'] ['1500'] ['万'] ['54946元/㎡'] ['273.0㎡\\xa0', '距昌平线西二旗步行1.8km'] ['2室2厅3卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['桃园公寓 明厨明卫 南北通透 平层三居室\\xa0'] ['393'] ['万'] ['27677元/㎡'] ['142.0㎡\\xa0'] ['3室2厅2卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['疯了！急出！带30平花园！南北通透！户型方正！价\\xa0'] ['588'] ['万'] ['68064元/㎡'] ['86.39㎡\\xa0', '距7号线百子湾步行1.1km'] ['2室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['西城区 玺源台 朝西正规一居室，有燃气，视野好 \\xa0'] ['608'] ['万'] ['97280元/㎡'] ['62.5㎡\\xa0', '距7号线湾子步行820m'] ['1室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['翠林漫步一期  南北通透 明厨明卫 带电梯\\xa0'] ['310'] ['万'] ['35884元/㎡'] ['86.39㎡\\xa0'] ['2室1厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['兴创荣墅老客户清退边户，关系房，赠送车位露台\\xa0'] ['1036'] ['万'] ['24667元/㎡'] ['420.0㎡\\xa0'] ['5室2厅4卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n",
      "['养老宜居 胜芳古镇 4A级景区 垂钓园 送小院 \\xa0'] ['29'] ['万'] ['2990元/㎡'] ['97.0㎡\\xa0'] ['3室2厅1卫', '\\n                                                                                    ', '\\n                                        \\n                                         -                                                                                     ', '\\n                                                                                 -                                                                                     ', '\\n                                                                            ']\n"
     ]
    }
   ],
   "source": [
    "for li_item in li_list:\n",
    "    title = li_item.xpath('.//div[@class=\"list-info\"]/h2[@class=\"title\"]/a/text()')\n",
    "    title = [t.replace(',', '，') for t in title]\n",
    "    price = li_item.xpath('.//div[@class=\"price\"]/p[@class=\"sum\"]/b/text()')\n",
    "    wan = li_item.xpath('.//div[@class=\"price\"]/p[@class=\"sum\"]/text()')\n",
    "    money = price[0] + wan[0]\n",
    "    unit = li_item.xpath('.//div[@class=\"price\"]/p[@class=\"unit\"]/text()')\n",
    "    area = li_item.xpath('.//div[@class=\"list-info\"]/p[@class=\"baseinfo\"]/span[2]/text()')\n",
    "    huxing = li_item.xpath('.//div[@class=\"list-info\"]/p[@class=\"baseinfo\"]/span[1]/text()')\n",
    "    print(title, price, wan, unit, area, huxing)\n",
    "    \n",
    "#     info = []\n",
    "#     info.extend(title)\n",
    "#     info.extend(price)\n",
    "#     info.extend(money)\n",
    "#     info.extend(area)\n",
    "#     info.extend(huxing)\n",
    "    \n",
    "    info_str = '{},{},{},{},{}'.format(title[0], money, unit[0], area[0], huxing[0])\n",
    "    write_file(info_str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
